<?php

/**
 * MyHammer IndexedMemcache
 *
 * LICENSE
 *
 * This source file is subject to the GNU General Public License Version 3
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.myhammer.de/opensource/license/gpl.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to opensource@myhammer.de so we can send you a copy immediately.
 *
 * @category   MyHammer
 * @package    IndexedMemcache
 * @subpackage example05_insertManyModels
 * @license    http://www.myhammer.de/opensource/license/gpl.txt GNU General Public License Version 3
 * @version    1.0
 * @author     Steven Berg <berg@myhammer.de>
 */

require_once '../../classes/class.autoloader.php';
require_once 'class.testModel.php';

/**
 * 
 * TEST OUTUT:
 * 
 * $iCountOfObjects = 10;
 * Step: 1 - Identifier: insert object direct       Duration:   000.089314 s
 * Step: 2 - Identifier: insert many objects        Duration:   000.105652 s
 *
 * $iCountOfObjects = 100;
 * Step: 1 - Identifier: insert object direct       Duration:   000.912053 s
 * Step: 2 - Identifier: insert many objects        Duration:   000.118916 s
 *
 * $iCountOfObjects = 1000;
 * Step: 1 - Identifier: insert object direct       Duration:   023.684034 s
 * Step: 2 - Identifier: insert many objects        Duration:   004.219257 s
 *
 */


$iCountOfObjects = 1000;

// flush Memcache
cMemCache::flush();
cProfiler::startPoint('insert object direct');
for($i = 0; $i< $iCountOfObjects; $i++) {
    $oTestModel = new cTestModel();
    $oTestModel->setId($i);
    $oTestModel->setEmail('test@example.com');
    $oTestModel->setUsername('myUsername');
    cMemCacheFiles::saveObject($oTestModel);
}
cProfiler::endPoint('insert object direct');


// flush Memcache
cMemCache::flush();
cProfiler::startPoint('insert many objects');
$aoMemCacheModels = array();
for($i = 0; $i< $iCountOfObjects; $i++) {
    $oTestModel = new cTestModel();
    $oTestModel->setId($i);
    $oTestModel->setEmail('test@example.com');
    $oTestModel->setUsername('myUsername');
    $aoMemCacheModels[] = $oTestModel;
}
cMemCacheFiles::saveObjects($aoMemCacheModels);
cProfiler::endPoint('insert many objects');
